#! python $this
import os,sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *




def __file2strbuf(filepath):
    b = QByteArray();
    io = QBuffer(b);
    io.open(QIODevice.WriteOnly)
    with open(filepath,"rb") as rf:
        data = rf.read(1024)
        while data:
            io.writeData(data)
            data = rf.read(1024)
    io.close()        
    return ''.join( ["%02X"%ord(c) for c in b.data()] )

def __strbuf2buf(strbuf):  
    buf = QByteArray();
    io = QBuffer(buf);
    io.open(QIODevice.WriteOnly)
    i=0
    while i < len(strbuf):
        hex = strbuf[i:i+2]
        io.write(chr(int(hex,16)))
        i+=2
    io.close()   
    return buf
    
def __getIcon_strbuf():
    return """89504E470D0A1A0A0000000D4948445200000080000000800806000000C33E61CB000000017352474200AECE1CE90000000467414D410000B18F0BFC6105000000097048597300000EC300000EC301C76FA8640000001974455874536F667477617265005061696E742E4E45542076332E352E38373B805D00000ED549444154785EED9D5D8C555715C737033330CC50AE53608056A028A41551D0946A300D820FB44619A341ACB60C6A077C11525B30D118F481BED9C4D498343195178D699A26FA607D224D1B8D5FA9F1C5D4978E5563357EC78F18ABC7F5C37BAE67EFBBF6F9BAE7DE39779FB3939349E69CB3EFD97BFDD7E75E7B6D63DAD6CE403B03ED0C3465062EC9401FCD715D69CA848438CEF77509BC2C7FFF2CD7BFE48A06B85E9177FF2617FD3D2917206A5B8D666049BEE5FB5D220D42E8A2EFFE537EF305B95A69B10260787A05089E0510000110F7AFC07C34E22711BD7F18409447AB44154C9B5599D7C4602A03A0A032AE36822A431E24DCF413B9FE5384F010799B591DED356BA2936626BA686E88BEB3E770E1EB9BB7DC1EBD5FDE3F60A6A21DD21FFD02A222DF22CFFE4AAEA3439EA7E0BA67C296F34EF4AC10669F998CCE9AD9C2442E038CF302A843666DB4D14C1401030629066ADB526600C2FF260FE1E1F01366FD48089E05922501DE6E913639550740683D090704F35D5199CA5173C27147CDBA5A10DD078A53A232360B387380183BA1550D5D632975C26E14C27F7BF71DB526BC0B886BAF796BF436511339A402364E231BFA10D7C94BFC9B849398C82C115CF7FB00418CC73443F6DF320F8D8A27807A2FE1F7883EAD3B51CB7CDF9BC49BC8500D780CA8C3601B6EDD3F7C93D0116B3E048ECF02C77CBA8D40E899E866700D11A78A41DCB87BC578CA9AB890EE7F425CC9A9F49802D1CE609A2AF267275647574CA751847741FC76F16A52D40291CFF15609E2AFAB7EFDBE75B3D139B3A1D1C48FC170599820451AB09A397EEB0B22D2E7F79B497CDD3E847F40C47D13747D51954534D3230DF012C6276670C6CCEEBFCD4CF6B97888FCAF9BCD2DD7A7AC4B9C15A9B85AB70DB09FEA1F4AFEA8107FCFD44C1F92B7AE59DB3843AFA804889F27E8C5C293471AD4378CEC233E8068F57DB1D54854E4463F08EA2709EE371BE635B17F70FA860823A72C3734FDBD2D7ACC0075502F9BE0A099EA33F8EE58DF698DBD1279082EE8C96B50D40186613DBC038975F7B97A707E6BE91713FB69D26EBB2E0930B457364E70DC4CF70579D0F9ADD8AF8EF831303C3601F9052BD3EE313357A656D9D62AD67E6BF0554F7C408044F57807CF8C1C0158FC103BA99BF0F39B16D31FB5918A8B38A9C70946BB802451BEBE553DE2DAA39E9026FEDE45B351330AF10C46630F687A5FA27F2DF1332CFEAFEC7863F4E84DAFEF5D8FDDFC86D273769799D640307C7BE0B4993DEBEA7D16765A8BFFFF7A1FC27E78EED5116E307393B2DAD7BBB773723AC273E2BDCF6F7F5D2E607862046C5F1B5E6350AEDE6F8DBEC3D167B7EE8DDE31BB29C20ECA43F03CCF30D79F9A7FAD371F12A653D60D86A70ACE98991FB91FFE0533970BAD21EAEA2777BD395AD8B8B552A2FB8001B8501FEE3CB217427987D4B26A9B70F9D6B9D5F67225080D91B05963FAEACE83D1DD1BB614E674C9107E4992439F11AE7D4EF2247ED931137FCA230992CFA0265C20B02741E9A75AAFE06E336D6DB3C60E689ACB870B76B2B32D93F042E8DF0A41BE26D727E53A22D7D60C76EC749FBB207F1F97EBA759C0B873662E62EB5A1C1F50B6AC41AF6ADA8366C3BBDC0F6A9AD58F8E7725A0332770F397E4BAB59A5937BBBA007AD1070698F0DC8D3BAF83403C330D98D51884EF36EBAD644E02404DB1FA19277A3E85239F977B0B1511DDD7CD71B971CDF70DA805A4816210B26034587B40B8DF75FBBE6C363542F763E469C92D5D4220A6874D78977847E41FDFD5808074BA5336A028F706DBA6FE4E47F7F34359465208F709DAB8A1EEEEE412017D58AE7583B1D6406F2F4A1229411F8BE030AA2205F8DE72EDA4597FCCE5FE074AEEB51F2750407C8F3F0FD71F28379B95BF8561A94A03450A944B239375FE97939DC1FDA1EBFE14E23F2573D1A99C8C8377F888A6129CFF959302AE080C9DFBD1F91EB1CF24D7B92DE60041E114B22F263B451584CCFD8C8D78BC329197EB4CF9C4B7E12978F75DCABD62DBD0C5C2F96B72328E05BED4EB89ECD59DF35D6CA64982422EE1BC1B590A7943070B2E0AE7A3F3C7B1117D1C784F012946BD4E4276FD08A0B8113E09E5FEACA6065F5E40025E0D0424EFE66A962E612FDF38B97145BED58DF2ADF9DF16F6AAC2B9B9267B080F75A44F2D84CCD872350B3DB21014240070F9C6D8E8CB22E482470A64EE2A2268D09B18022245386A9C9E65452D3956B17BA8FDBB9211BE2CA216BDAFA982CC0C622BCF9F491A27A2E6FD560FF7C3352135A2856EB5F4BF670DD0D2FFA1067F14B78F55BD10DB138A2A481DA72516434CFA20E8E3AE71C88C84C6FD3191772A0078C887004BFF1316CD2B52C7E939C5EFFF7588AC9F18D32F1C10BCE41B2F95A97A1220D49C3F37B359C6CCF26EC88DCCA0A464272AA81ABB6493F61E7C4F4D8A3157295D3CE27FDCFDFE2CF0DEABA88123DA4B9601F869D98254E5E4D7A12F326A9DC92060127A7B8B0280CBDAA0110DBD090A3100A464F53E1E3AF5657C1D0500E418F6358B3B42DCE3AFE8FF730D000043FC9D0382BE7D848408838F002A091F88C726B46F295200C9D06BD4F2ED0180E4883AE8EC2ABF0103306B12024602AACE1DBF057E4ED4EC3D40AE7995935F87BE48F972262174FF3F896736ADB8E33F957CC0F215438C01B06DDB99841F07CCF1EED02E2B00584C3E642581849802E6BA806CD26C38002E340A00145E4872C15A63BED7700020157A8D634F7B13D44A80E0A0A1A900F2077BAD892AE007C191D93FA0D60670BD00C900FA790B008F04E0A8B33AB86E557E03051E144B38A414B0343C6B12E048F285E0E3008049D9F479A02152E01105FC56E5120B009437AB92FBEAD29752B6CD0A86040C063735AC6FA790B516106A369052ED03CE6842732BBC712299D5A83D6FE9C81037832AE960EAB2688088F8BD43DF67B5315A00786F8019416C0573268224984E80044F0E0943D71DF7A23666EBA4AF508B402A757F42CF09585000A082DE3AF923D43D819456732684522B21B76F38E3F56E15B7C2C121C602F046946561007120500420FEFFE200C05B55DC4A0A4154D6C57DABFA3BC8777026E5A94001704111FF3FF48DB5CF1308312F10303DBCED562D2A189A1480FB497A71C74ACC476F52C0D8CA0C0EB928A4620C8626057CD542FC278BDCEC9CF61DE2B270AC4E3C5280624B2134C2BC5AD1A8F422D2527ADC4A0D0B3522188340090D530C328405222D0B1855B09C8AEE4366AACF0E08F944104F9D807157059AE117DB017EFD1F23C3D58DA1D60888A580E70C0026711C1BA9DE69F502FDFA3F1EAD1CFF8698E8598EA1AE0CC600482912396EF6C02EA1DB1F15AB3FA625E73B67B70F9A196B65900E432C14918C2D700C8C5234024E3A903D63B57802E2BF98427C4090FF00093750126A583809024E055126108EAABB24C8437CC6962DFE632CCB2921569268E8DE400C848736EFD640802458AC059FF77F043ABF4FEC4BBD43771CB98B445EFF89FBCDEC7C534F0AE1F0468F282579A44E2EE205F99E3E83EF981C31A77C7FF133036E3753D6A91421AF0DB86B0D1E49C0C4B272B8D23B8A09F2A87E3ED5CF7698BEC32B0B158AEE09990F9919AB6814A80AB968B40B0222858A61187317D2A0B3026A81F0AE6AE923B93E63EC935DBB9220BFF1E70EC83D253CD4C291BED54602459E7304000284B83C0220A07610F7DAC2CEF54C67C0CA1814EEE73BCB374D0A84982A96B6DCCC7E828C93420102DBAFAB560D14AFA282994A78B89B180DF90D7CBF87FB8B1D14A141E5363369A58A85583B204FBE019B4B53A441AC1AF0C50103E9E656DE7D0E3644A52C7489FE7C577CAB062925EE49704D7EB72CE469CFE677FD7C1F281CEFD6998B42CD17CC020251C3F39B6EC93A45344908A4C3B52E285017EE852DC17D2F972781804D42E81AA994FCD625FD10E9C1B93F06851B186AC2096269602801049F6B99EBFFE879081F9F17EC7E9B6C751F0EF7C700B8CFCC2CB91671888524B32480761FD5C0F1EE6922BBEC3D180F519FB64783DC4DA5FFF296BF4F151C31EBAC4AA200A269066196B188350EA7A61C399B0A146C0C762F1196F6717BF21B5005CAC9E1D86CD537A283EEF93A58A121EE202A2309B4775864A2340DA9E8F8E9DAC57DDCCD32BFB95937FC324F05298D0ECD206C55C1E152C42B43F0E43B1ED1BF5C9AB8795F3C68A65857B64459C8C9A383126A18EF9F97339C15BDCFA15083BB7D5940F88899DDEF56DCC44A0D39756C18442CDB272A5739251C402C65D1AEB2FBF798992BAE57D0DA03A35105DB75BD9F79185465C48F3B3A6EA6AD03A61049A16E272BCBAD55BFB7D7ACD144BF77AB57E544773B74178B00416B140E4712788CBED1E87D1F92B007B4F8F819094D568DFE26F777426A35788249A3D3FB3E109C962452A50C7B7445D6A69B4CB4AAC6BEE0273E9B79EBD1246B7849A9C0157DCC6C6841204BB565C19042FCABF5A07CE22B4E98E94B5A064D8847CF94256891F73C3A1F55307A8B3F2FDAB69B89AB1A08184C1B32CE2F09F699499FCEAF2FF11320B9A4052A58D9FA5C6B17A4AA0398C493D6556FCE572404D6292E8A856416934EB71E820A02C2BB93FABA3E73583F9D9F432D1C9567AC821331201E94C116D187A13F7BD4AC4B5B26AE8FB59F83E8FDB1A2FE23CCAF0F566A11E45AF30E99F8ACE77B42BBCC1112B4F8868E12441AC52BCB9E404684C11332917D6383EB95648E5812B0E24AAD86A09A55903A090874DF7D0DB10D3E2EEA6FDAAC4A13F994EB0BB6611750A7469D802DB2D29527156A1C2506E21EB5E71B7B57E4AF7C687744D0B38A52BA9302102E66188A8F9957BD3C0E4000D07BD2090F28C8B71C7E32C788889BF7679006D606540D0867C75435B053C7B35923290548E06C0CD7FB80819BD317334882615674E6B84413EF32D391D45B4C1D4F776C4FE7E594A63C47983373E2C8846591A44EE29F9D39B87329567D92EBF18882B3F0AB042940500348AE8A983313D1215967208A364A40A0D79148D82A13FEE89D6BF09141D5383D3F0830D8DDF24A8AD56C4D30848020A44D9D3433958102629F92FE8857C0E59E844C9F758F441B8B059C410835EC77D9E880959CA91E34B0B06F0E490130F25EA8990C5F3D6B2B1867F28C750877D8442DDB3F8B22A99E435E893184E7A8D78361D78AF9B2D4EDBE27D23C5783C35E90CBAA5F3004C2FAB81DF5846402942DD173916CB80F018865B92889E68D36960408FD2179E8BF25F870E9E8EDBD6C8936D620B8205EDE0B22F34ECBD92B44ECAC9F2D0B86AC7E1B75FFBF2FD9391E4779E2410000000049454E44AE426082"""

def getPixMap():
    pm = QPixmap()
    buf = __strbuf2buf(__getIcon_strbuf())
    pm.loadFromData(buf,"png")
    return pm

if __name__ == "__main__":
    img = "./icon.png"
    app = QApplication(sys.argv)
    # turn the image into a string buffer
    strbuf = __file2strbuf(img)
    print strbuf
    # turn the string buffer into byte array
    buf = __strbuf2buf(__getIcon_strbuf())
    # save the buffer as a png file
    pm = QPixmap()
    pm.loadFromData(buf,"png")
    pm.save("./temp-icon.png")
